package Backtracking;

import java.util.ArrayList;
import java.util.List;

public class _77_Combinations {
    List<List<Integer>> res;
    int end;
    int len;
    boolean[] check;
    public List<List<Integer>> combine(int n, int k) {
        this.res = new ArrayList<>();
        this.end = k;
        this.len = n;
        this.check = new boolean[n + 1];
        bc(new ArrayList<>(), 0, 1);
        return res;
    }

    public void bc(List<Integer> list, int count, int pos) {
        if (count == end) {
            res.add(list);
        } else {
            for (int i = pos; i <= len; i++) {
                List<Integer> tlist = new ArrayList<>(list);
                tlist.add(i);
                bc(tlist, count + 1, i + 1);
            }
        }
    }
}
